package cn.iocoder.yudao.module.study.formatResult.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.study.formatResult.annotation.FormatResult;
import cn.iocoder.yudao.module.study.formatResult.annotation.IgnoreFormatResult;
import cn.iocoder.yudao.module.study.formatResult.controller.admin.vo.StudentUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author cjc
 * @Date 2024/5/16 16:42
 * @Description: 格式化结果 Controller
 * @Version 1.0
 */
@RestController
@RequestMapping("/format/result")
@Slf4j
public class FormatResultController {

    @GetMapping("test11")
    @FormatResult
    public List<StudentUserVO> test11(){
        return studentList();
    }

    @GetMapping("test12")
    @FormatResult
    public CommonResult<StudentUserVO> test12(){
        return success(studentList().get(0));
    }

    @GetMapping("test13")
    @FormatResult
    public CommonResult<List<StudentUserVO>> test13(){
        return success(studentList());
    }

    @GetMapping("test14")
    @FormatResult
    public CommonResult<PageResult<StudentUserVO>> test14(){
        PageResult<StudentUserVO> pageResult = new PageResult<>();
        pageResult.setList(studentList());
        pageResult.setTotal(3L);
        return success(pageResult);
    }

    @GetMapping("test15")
    @FormatResult
    @IgnoreFormatResult
    public CommonResult<PageResult<StudentUserVO>> test15(){
        PageResult<StudentUserVO> pageResult = new PageResult<>();
        pageResult.setList(studentList());
        pageResult.setTotal(3L);
        return success(pageResult);
    }

    @GetMapping("test16")
    @FormatResult
    public CommonResult<String> test16(){
        return success("xxx");
    }

    @GetMapping("test17")
    @FormatResult
    public CommonResult<Boolean> test17(){
        return success(true);
    }

    @GetMapping("test18")
    @FormatResult
    public CommonResult<Long> test18(){
        return success(10086L);
    }


    @GetMapping("test21")
    @FormatResult(formatAsExtra = true)
    public List<StudentUserVO> test21(){
        return studentList();
    }

    @GetMapping("test22")
    @FormatResult(formatAsExtra = true)
    public CommonResult<StudentUserVO> test22(){
        return success(studentList().get(0));
    }

    @GetMapping("test23")
    @FormatResult(formatAsExtra = true)
    public CommonResult<List<StudentUserVO>> test23(){
        return success(studentList());
    }

    @GetMapping("test24")
    @FormatResult(formatAsExtra = true)
    public CommonResult<PageResult<StudentUserVO>> test24(){
        PageResult<StudentUserVO> pageResult = new PageResult<>();
        pageResult.setList(studentList());
        pageResult.setTotal(3L);
        return success(pageResult);
    }

    @GetMapping("test25")
    @FormatResult(formatAsExtra = true)
    @IgnoreFormatResult
    public CommonResult<PageResult<StudentUserVO>> test25(){
        PageResult<StudentUserVO> pageResult = new PageResult<>();
        pageResult.setList(studentList());
        pageResult.setTotal(3L);
        return success(pageResult);
    }

    @GetMapping("test26")
    @FormatResult(formatAsExtra = true)
    public CommonResult<String> test26(){
        return success("xxx");
    }

    @GetMapping("test27")
    @FormatResult(formatAsExtra = true)
    public CommonResult<Boolean> test27(){
        return success(true);
    }

    @GetMapping("test28")
    @FormatResult(formatAsExtra = true)
    public CommonResult<Long> test28(){
        return success(10086L);
    }

    private static List<StudentUserVO> studentList(){
        List<StudentUserVO> list = new ArrayList<>();
        for (long i = 0;i<3;i++){
            StudentUserVO vo = new StudentUserVO(i,getName(),getSex(),i == 1?null :getIdCard());
            list.add(vo);
        }
        return list;
    }

    private static int getRandom(int n){
        Random random = new Random();
        //生成一个 0 ~ (n-1)的随机数
        return random.nextInt(n);
    }

    private static String getName(){
        int random = getRandom(70);
        String[] strings = new String[]{"张三","李四","黄伟群","黄伟群","邱慎明","邱慎明","邱惠芬","邱惠芬","陈卫军","陈卫军","赵桂枝","赵桂枝","黄若明","黄若明","汪丽丽","汪丽丽","游远方","游远方","蔡世峰","蔡世峰","郑燕穗","郑燕穗","叶均杰","叶均杰","王惠","王惠","卢家儒","卢家儒","谭海","谭海","何军健","何军健","詹宋强","尤小蓉","尤小蓉","李文送","李文送","黎康丽","黎康丽","黄金雄","黄金雄","黄东梅","黄东梅","朱锐","刘小丰","刘小丰","叶楚龙","叶楚龙","林惠莉","林惠莉","杨美珍","杨美珍","何小霞","黄小华","黄小华","方榕彬","曹雅婷","曹雅婷","侯燕香","侯燕香","屈冬林","周洁珍","周洁珍","周洁珍","罗卓君","罗卓君","罗卓君"};
        int max = random>=strings.length?0:random;
        return strings[max];
    }

    private static int getSex(){
        int random = getRandom(3);
        int[] ints = new int[]{0,1,2};
        int max = random>=ints.length?0:random;
        return ints[max];
    }

    private static String getIdCard(){
        int random = getRandom(5);
        String[] strings = new String[]{"01","02","03","04","05"};
        int max = random>=strings.length?0:random;
        return strings[max];
    }

}
